package com.example.demo.config;

import com.dtflys.forest.config.ForestConfiguration;
import com.dtflys.forest.springboot.annotation.ForestScan;
import com.dtflys.forest.ssl.SSLUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: Bin.L
 * @date: 2021/11/19 0019 15:05
 * @Description:
 */
@Configuration
@ForestScan(basePackages = "com.example.demo.service.invoke")
public class ForestConfig {

    @Bean
    public ForestConfiguration forest() {
        ForestConfiguration configuration = ForestConfiguration.configuration();
        configuration.setBackendName("okhttp3");
        // 连接池最大连接数，默认值为500
        configuration.setMaxConnections(20);
        // 每个路由的最大连接数，默认值为500
        configuration.setMaxRouteConnections(100);
        // 请求超时时间，单位为毫秒, 默认值为3000
        configuration.setTimeout(3000);
        // 连接超时时间，单位为毫秒, 默认值为2000
        configuration.setConnectTimeout(2000);
        // 请求失败后重试次数，默认为0次不重试
        configuration.setRetryCount(3);
        // 单向验证的HTTPS的默认SSL协议，默认为SSLv3
        configuration.setSslProtocol(SSLUtils.SSL_3);
        // 打开或关闭日志，默认为true
        configuration.setLogEnabled(true);
        return configuration;
    }
}
